home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.4 / AppShell / Examples / Clipboard / sprite.c < prev   
Encoding:
C/C++ Source or Header  |  1992-09-01  |  2.7 KB  |  107 lines

  1. /* sprite.c
  2.  * convert an ILBM record to a sprite.
  3.  * Written by David N. Junod
  4.  *
  5.  */
  6.  
  7. #include <exec/types.h>
  8. #include <exec/libraries.h>
  9. #include <exec/memory.h>
  10. #include <iff/ilbm.h>
  11. #include <intuition/intuition.h>
  12. #include <intuition/intuitionbase.h>
  13. #include <graphics/gfx.h>
  14. #include <graphics/displayinfo.h>
  15. #include <graphics/sprite.h>
  16. #include <libraries/prefs.h>
  17. #include <clib/macros.h>
  18. #include <clib/exec_protos.h>
  19. #include <clib/intuition_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <pragmas/exec.h>
  22. #include <pragmas/intuition.h>
  23. #include <pragmas/graphics.h>
  24. #include <string.h>
  25.  
  26. extern struct Library *GfxBase, *IntuitionBase;
  27.  
  28. ILBM *ReadILBM (BPTR drawer, STRPTR name, struct TagItem * attrs);
  29. VOID FreeILBM (ILBM * ilbm);
  30.  
  31. /* extra memory (in bytes ) allocated for control info and terminator    */
  32. #define SPMEM_EXTRA        ( 2 * sizeof (short int) + 2 *  sizeof (short int))
  33. #define SPMEM_BYTES( height )    (SPMEM_EXTRA+2*sizeof (short int) *(height))
  34.  
  35. /* word index to reserved at bottom    */
  36. #define SPMEM_RSRVD( height )     (2 + 2 * (height))
  37. #define    SPRF_FORCED    (1)
  38.  
  39. struct PointerPref *MakePointer (ILBM * ilbm)
  40. {
  41.     struct PointerPref *pp = NULL;
  42.     struct RastPort *srp = &(ilbm->ir_RPort);
  43.  
  44.     /* Allocate the preference structure */
  45.     if (pp = (struct PointerPref *) AllocVec (sizeof (*pp), MEMF_CLEAR))
  46.     {
  47.     /* Setup the dimension information */
  48.     pp->pp_Height = ilbm->ir_Height;
  49.     pp->pp_Width = 16;    /* ilbm->ir_Width; */
  50.     pp->pp_XOffset = -(ilbm->ir_Grab.x);
  51.     pp->pp_YOffset = -(ilbm->ir_Grab.y);
  52.  
  53.     /* Calculate size of sprite data */
  54.     pp->pp_DSize = (LONG) SPMEM_BYTES (pp->pp_Height);
  55.  
  56.     /* Allocate sprite data */
  57.     if (pp->pp_PData = (UWORD *) AllocVec (pp->pp_DSize, MEMF_CLEAR | MEMF_CHIP))
  58.     {
  59.         /* Lotsa stack */
  60.         struct BitMap spr_BMap = {NULL};
  61.         struct RastPort spr_RPort = {NULL};
  62.         struct RastPort *drp = &spr_RPort;
  63.         struct BitMap *dbm = &spr_BMap;
  64.  
  65.         /* Setup position control terminator */
  66.         pp->pp_PData[SPMEM_RSRVD (pp->pp_Height)] = 0;
  67.         pp->pp_PData[SPMEM_RSRVD (pp->pp_Height) + 1] = 0;
  68.  
  69.         /* Initialize the bitmap */
  70.         InitBitMap (dbm, 2L, 32L, (LONG) pp->pp_Height);
  71.  
  72.         /* Do weird magic with the planes */
  73.         dbm->Planes[0] = (PLANEPTR) (pp->pp_PData + 2);
  74.         dbm->Planes[1] = (PLANEPTR) (pp->pp_PData + 3);
  75.  
  76.         /* Initialize the RastPort */
  77.         InitRastPort (drp);
  78.         drp->BitMap = dbm;
  79.         SetRast (drp, 0);
  80.  
  81.         /* Copy the ILBM into the sprite */
  82.         ClipBlit (srp, 0, 0, drp, 0, 0, pp->pp_Width, pp->pp_Height, 0xC0);
  83.     }
  84.     else
  85.     {
  86.         FreeVec ((APTR) pp);
  87.         pp = NULL;
  88.     }
  89.     }
  90.  
  91.     return (pp);
  92. }
  93.  
  94. VOID FreePointer (struct PointerPref * pp)
  95. {
  96.  
  97.     if (pp)
  98.     {
  99.     if (pp->pp_PData)
  100.     {
  101.         FreeVec (pp->pp_PData);
  102.     }
  103.  
  104.     FreeVec (pp);
  105.     }
  106. }
  107.